<?php
class Paper_list extends Controller{
    
    function Paper_list(){
        parent::Controller();
        $this->load->library('session');
	    if($this->session->userdata('admin') == '')
    	{
    		 redirect('admin');
    	}
       
         $this->load->helper(array('form','tiap_helper','html'));
       $this->load->library('form_validation'); 
         $this->load->model('paper_list_model');
    }
    
    
    function index(){
        
        	$data = array();
    	$order_by = $this->uri->segment(4);
    
		 $page = (int)$this->uri->segment(5);
		
		$page = ($page == '')?0:$page;
		$order_by = ($order_by == '')?'order':$order_by;
	   	$per_page = 15;
    	$data['total_paper_list'] = $this->paper_list_model->total_paper_list();
		// pagination start
		$this->load->library('pagination');
		$config['base_url'] = site_url('admin/paper_list/index/'.$order_by);
		$config['total_rows'] = $data['total_paper_list'];
		$config['per_page'] = $per_page;
	
		$config['uri_segment'] = 5;

		$this->pagination->initialize($config); 

		$data['pagination'] =  $this->pagination->create_links();
		//pagination end
    	$data['order_by'] = $order_by;
    	
        
        
      $data['paper_list']=$this->paper_list_model->list_paper_list($per_page,$page,$order_by);  
       $data['page']=$page;
		$this->load->view(TEMPLATE_NAME.'/admin/paper_list/list',$data);
        
    }
    function detail(){
        
        	$data = array();
    	    $id = (int)$this->uri->segment(4);
            $page = (int)$this->uri->segment(5);
            $data['page']=$page;	
			$data['paper_list_detail']=$this->paper_list_model->get_paper_list_detail($id );
			$this->load->view(TEMPLATE_NAME.'/admin/paper_list/detail',$data);
        
    }
    function delete(){
		  
         $id= $this->input->post('papers');
            
         $check= $this->paper_list_model->delete_paper_list($id);
        
           redirect('admin/paper_list');
        
		}
        
   function form(){
		  
         	$data = array();
    	    $id = (int)$this->uri->segment(4);
             $page= (int)$this->uri->segment(5);
            $data['page']=$page;
            $data['paper']=$this->paper_list_model->get_paper_list_detail($id );
			$this->load->view(TEMPLATE_NAME.'/admin/paper_list/action',$data);
        
		}
  function action(){
        $page= $this->input->post('page');
        $data['page']=$page;
         $this->form_validation->set_error_delimiters('<div class="error">','</div>');   
         $this->form_validation->set_rules('paper_title','Paper Name','callback_paper_title');
           $this->form_validation->set_rules('paper_colour','Paper ColourType','required');
             $this->form_validation->set_rules('paper_size','Grammage/GSM','required|numeric');
         $this->form_validation->set_message('required','Please enter %s');
          $this->form_validation->set_message('numeric','Please enter numeric value %s');
         if($this->form_validation->run() == False){
            $this->load->view(TEMPLATE_NAME.'/admin/paper_list/action',$data);
            }else{
            $this->paper_list_model->do_action();
            
             redirect('admin/paper_list/index/'.$page);
             }
        
		}
        
    function paper_title($str){
       // $check=$this->paper_list_model->check_paper_title($str);
        if($str=='')
        {
            
         $this->form_validation->set_message('paper_title','Please enter %s');
         return false ; 
        }/**
 * elseif($check){
 *             
 *              $this->form_validation->set_message('paper_title','Please enter another %s');
 *             return False;
 *         }
 */else{
            return True;
           
        }
        
        
        
    }
    
}
?>